import pandas as pd
import matplotlib.pyplot as pt
df=pd.read_excel("某公司各部门1—2月份实际支出.xlsx")
x=df['部门']
height=df['1月']
pt.figure(figsize=(8,4))
pt.rcParams['font.sans-serif']='SimHei'

#3-1单柱形图
# pt.title('某公司各部门一月份实际支出单柱形图')
# pt.ylabel('实际支出（元）')
# for a,b in zip(x,height):
#     pt.text(a,b,'%d'%b,ha='center')
# pt.bar(x,height,0.4,color='teal')
# pt.legend(('一月',))
# pt.show()

#3-2簇状柱形图
import numpy as np
pt.title('某公司各部门1—2月份实际支出簇状柱形图')
pt.ylabel('实际支出（元）')
x_data = np.arange(len(df['部门']))
height_data = [ ]
height_data.append(df['1月'])
height_data.append(df['2月'])
width = 0.4
for i in range(len(height_data)):
   x = x_data + i * width
   height = height_data[i]
   pt.bar(x,height,width)
   for a,b in zip(x,height):
      pt.text(a,b,'%d' % b,ha='center')
pt.xticks(x_data + 0.2,df['部门'])
pt.legend(('1月','2月'))
pt.show()

#3-3堆积柱形图
# pt.title('某公司各部门1—2月份实际支出堆积柱形图')
# pt.ylabel('实际支出（元）')
# width=0.4
# pt.bar(x,df['1月'],width,color='green')
# pt.bar(x,df['2月'],width,bottom=df['1月'],color='salmon')
# for a,b,c in zip(x,df['1月'],df['2月']):
#     pt.text(a,b/2,'%d' % b,ha='center',va='center')
#     pt.text(a,b + c / 2,'%d' % c,ha='center', va='center')
# pt.legend(('1月','2月'))
# pt.show()

